<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

<title>电子文档系统</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<script type="text/javascript" src="view/jquery/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="view/js/docMan.js"></script>
	<script type="text/javascript" src="view/bootstrap/js/bootstrap.js"></script>
<link rel="stylesheet" href="view/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="zcfg/css/menu_left.css" media="screen" />
<style type="text/css">

	#menu ul {
	padding-left: 15px;
	/* height: 300px; */
	height:auto;
	border: #E7E7E7 0px solid;
	border-top: none;
	overflow: auto;
	}
	#menu span{
		padding:4px 4px;
		/* min-height:25px; */
		font-size: 14px;
	}
	#menu span:HOVER {
		background-color: #277fc2;
		font-color: #fff;
		color: #fff;
	}
	.dbclick{
		background-color: #277fc2;
		font-color: #fff;
		color: #fff;
	}
</style>
</head>

<body style="background: #EDEFF0;">
	<div class="top" style="position: inherit;">
		<div style="float: left">
			<span
				style="font-size: 16px;line-height: 45px;padding-left: 20px;color: #fff；margin-left:30px;">公文浏览</span>
		</div>
		<div style="float:left">
			<span
				style="font-size: 16px;line-height: 45px;padding-left: 20px;color: #fff">
			</span>
		</div>
		<div style="float:right" id="ad_setting" class="ad_setting">
			<a class="ad_setting_a" href="javascript:;"></a>
		</div>
	</div>
	<div id="menu" class="left-menu" style="width:15%;">
		<ul>
			<s:iterator value="bookPage.result" id="book" status="stu">
				<li ><span id='<s:property value="#book.id"/>' class="fatherBook" style="display:block;"><span class="glyphicon glyphicon-plus" style="float:left; font-family:-webkit-pictograph;" aria-hidden="true"></span><s:property value="#book.bookName"  /></span>  </li>
			</s:iterator>
		</ul>
	</div>
	<div id="show_hide_btn" style="float:left;margin-left:15%;height:100%;vertical-align: middle;width:30px;;background-color: #ffffff;padding-left:5px;cursor: pointer;">
		<span class="glyphicon glyphicon-chevron-left" id="show_icon" style="position:absolute;top:48%;font-size:20px;" >
		</span>
	</div>
	<div class="right-content" style="margin-left:16%;">
		 <div class="content">
        <div id="page_content">
            <iframe id="pdfIframe" name="" src="" style="overflow:visible;"
                    scrolling="yes" frameborder="no" width="100%" height="100%"></iframe>
        </div>
    </div>		
	</div>
</body>
</html>

<script type="text/javascript">
	//定义setTimeout执行方法
	var TimeFn = null;
	
	
	$("#menu").on("click",".bookSon",function(){
		// 取消上次延时未执行的方法
	    clearTimeout(TimeFn);
	    var span=$(this);
	    //执行延时
	    TimeFn = setTimeout(function(){
	       var bookSonId=$(span).attr("id");
			var li=$(span).closest("li");
			showplusmins(span);
			if($(li).find("ul").length==0){
				$.ajax({
					type:"post",
					url:"/DocMan/webService/show/DocBookSon/getSubBookSon",
					data:{bookSonId:bookSonId},
					success:function(data){
						console.info(data)
						var groupClassId="group"+bookSonId;
						var s="<ul>";
						$(data["bookSons"]).each(function(i,ele){
							s=s+"<li ><span class='bookSon' id="+ele.id+" title=\"双击查看文档\"  style=\"display:block;\"> <span class=\"glyphicon glyphicon-plus\" style=\"float:left; font-family:-webkit-pictograph;\" aria-hidden=\"true\"></span> "+ele.subTitle+"</span></li>";
						});
						s=s+"</ul>";
						$(li).append(s);
					},
					error:function(data){
						toast.error("请求失败", "温馨提示");
					}
				});
			}else{
				$(li).find("ul").toggle(500);
			}
	    },300);
		return false;
	})
	$("#menu").on("dblclick",".bookSon",function(){
		var bookSonId=$(this).attr("id");
		 clearTimeout(TimeFn);
		 $("span").removeClass("dbclick");
		 $(this).addClass("dbclick");
		showPdf(bookSonId)
	});
	$(".fatherBook").on("click",function(){
		var fatherBookId=$(this).attr("id");
		showplusmins($(this));
		var li=$(this).closest("li");
		if($(li).find("ul").length==0){
			$.ajax({
				type:"post",
				url:"/DocMan/webService/show/DocBookSon/getBookSonByFatherId",
				data:{fatherBookId:fatherBookId},
				success:function(data){
					console.info(data);
					var s="<ul>";
					$(data.bookSons).each(function(i,ele){
						s=s+"<li  ><span class='bookSon' id="+ele.id+" title=\"双击查看文档\"  style=\"display:block;\"><span class=\"glyphicon glyphicon-plus\" style=\"float:left; font-family:-webkit-pictograph;\" aria-hidden=\"true\"></span> "+ele.subTitle+"</span></li>";
					});
					s=s+"</ul>";
					$(li).append(s);
				},
				error:function(){
					
				}
			});
		}else{
			$(li).find("ul").toggle(500);
		}
	});
	$("#show_hide_btn").on("click",function(){
		if($("#show_icon").hasClass("glyphicon-chevron-left")){
			$("#show_icon").removeClass("glyphicon-chevron-left");
			$("#show_icon").addClass("glyphicon-chevron-right");
			$("#menu").toggle();
			$(".right-content").css("margin-left",0);
			$(this).css("margin-left",0);
		}else{
			$("#show_icon").removeClass("glyphicon-chevron-right");
			$("#show_icon").addClass("glyphicon-chevron-left");
			$(".right-content").css("margin-left","16%");
			$(this).css("margin-left","15%");
			$("#menu").toggle();
		}
	})
	function hideleft(){
		$("#show_icon").removeClass("glyphicon-chevron-left");
		$("#show_icon").addClass("glyphicon-chevron-right");
		$("#menu").toggle();
		$(".right-content").css("margin-left",0);
		$("#show_hide_btn").css("margin-left",0);
	}
	function showleft(){
		$("#show_icon").removeClass("glyphicon-chevron-right");
		$("#show_icon").addClass("glyphicon-chevron-left");
		$(".right-content").css("margin-left","16%");
		$("#show_hide_btn").css("margin-left","15%");
		$("#menu").toggle();
	}
	function showPdf(bookSonId){
		//var url="/DocMan/webService/show/DocBookSon/getBookSon/"+bookSonId;
		var url="officeFilePreview.action?bookSonId="+bookSonId;
		var height = $(window).height();
		var width = $(window).width();
		$("#pdfIframe").attr('src', url);
	}
	function showplusmins(span){
		console.info($(span).find("span").hasClass("glyphicon-plus"));
		if($(span).find("span").hasClass("glyphicon-plus")){
			$(span).find("span").removeClass("glyphicon-plus");
			$(span).find("span").addClass("glyphicon-minus");
		}else{
			$(span).find("span").addClass("glyphicon-plus");
			$(span).find("span").removeClass("glyphicon-minus");
		}
	}
</script>
